package com.GameSpace.CoreAssets;


import java.util.Calendar;

import com.GameSpace.SameGame.R;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.TextView;

abstract public class CountDownManager extends LinearLayout{
	private TextView tvs;
	

	private float opacityLevel;//ranges from 0 to 1. 1 means countdown screen is fully opaque. 
						//In these case a background image should be determined.
    
	
	private Drawable background;	//	This will be used if opacityLevel set to 1.
		
	
	private float fontSize;		//	determines the font size of the countdown screen
	
	
	private Typeface fontType;	//	determines the font type for the countdown screen
	
	
	private int countDownTime;//determines the how many seconds should be counted down
	private Animation animation;
	
	
	public CountDownManager(Context context) {
		super(context);
		fontSize=80;
		opacityLevel=0;
		countDownTime=3;
		fontType=Typeface.DEFAULT;
		tvs=(TextView) findViewById(R.id.text);
		// TODO Auto-generated constructor stub
	}

	/*	
	METHODS HERE
	 */
	
	public void set_opacityLevel(float level){
		opacityLevel=level;
	}
	public float get_opacityLevel(){
		return opacityLevel;
	}
	public void set_background(int id){
		background = this.getResources().getDrawable(id);
	}
	public void set_fontSize(float size){
		fontSize=size;
	}
	public float get_fontSize(){
		return fontSize;
	}
	public void set_fontType(Typeface font){
		fontType=font;
	}
	public Typeface get_fontType(){
		return fontType;
	}
	public void set_countDownTime(int time){
		countDownTime=time;
	}
	public float get_countDownTime(){
		return countDownTime;
	}
	
	public void decreaseTime(long millisUntilFinished){
		
		
	}
	abstract public void  finishCountDown();
				//Starts countdown
	
	public void startCountDown(final TextView tv,View as){
		//this.addView(tv);
		tvs=(TextView)findViewById(R.id.text);
        animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(9000);
        if(opacityLevel==1){
        	as.setBackgroundDrawable(background);
        	
        }
           tv.setTextSize((int)fontSize);
           tv.setTypeface(fontType);
           animation = new AlphaAnimation(1.0f, 0.0f);
           animation.setDuration(1000);
           new  CountDownTimer(countDownTime*1000+150, 1000) {
            public void onTick(long millisUntilFinished) {
            	if(millisUntilFinished/1000<2){
            	    animation.setDuration(1100);
            	    tv.setAnimation(animation);
	            	tv.setText(String.valueOf((millisUntilFinished/1000)));
	            	tv.startAnimation(animation);
            	}
            	else{
	            	tv.setAnimation(animation);
	            	tv.setText(String.valueOf((millisUntilFinished/1000)));
	            	tv.startAnimation(animation);
            	}
            }

            public void onFinish(){
            	finishCountDown();
            }
         }.start();
         
	}
        
    
}
